﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Interactivity;

namespace OmniKits.Windows.Behaviors
{
    class AutoSyncSecurePasswordBehavior
        : Behavior<PasswordBox>
    {
        protected override void OnAttached()
        {
            AssociatedObject.PasswordChanged += PasswordChanged;
            AssociatedObject.SyncSecurePassword(true);
        }

        private void PasswordChanged(object sender, RoutedEventArgs e)
        {
            AssociatedObject.SyncSecurePassword();
        }

        protected override void OnDetaching()
        {
            AssociatedObject.PasswordChanged -= PasswordChanged;
        }
    }
}
